package com20230217;

public class Person {
    //定义成员变量
    private String name;
    private int age;
    private String gender;

    //定义getter/setter方法
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        if (age > 150 || age < 0){
            System.out.println("输出错误，年龄" + age + "不合法，请重新输入");
            return;
        }
        this.name = name;
    }
    public String getGender(){
        return gender;
    }
    public void setGender(String gender){
        if ("男".equals(gender) || "女".equals(gender)){
            this.gender = gender;
        }else{
            System.out.println("性别不合法");
        }
    }
    //无参构造
    public Person(){
        this.name = "无名氏";
        this.age = 18;
        this.gender = "男";
    }
    //有参构造
    public Person(String name,int age,String gender){
        this.name = name;
        this.age = age;
        this.gender = gender;
    }
    public void say(){
        System.out.println("自我介绍一下，我叫" + name + "，今年" + age + "岁了，我是一个" + gender + "孩子");
    }

}
